package leedcode_path.Link;

public class 环形链表2 {
    public ListNode detectCycle(ListNode head) {
        ListNode fast=head;
        ListNode slow=head;
        while (fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
            if (fast==slow){
//                证明相遇了
                ListNode cur=fast;
                ListNode flag=head;
                while (cur!=flag){
                    cur=cur.next;
                    flag=flag.next;
                }
                return cur;
            }

        }
        return null;

    }
}
